package com.marvels.approve.manager.controller;

import com.github.pagehelper.PageInfo;
import com.marvels.approve.manager.dto.ApprovalProcessConditionDTO;
import com.marvels.approve.manager.dto.ApprovalProcessInfoDTO;
import com.marvels.approve.manager.dto.ApproveManageScreeneDTO;
import com.marvels.approve.manager.service.ApproveManagerService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 运营流程-审批管理-审批流程
 * @author tangpw
 *
 */
@RestController
@RequestMapping("approve/approvalManagement/approvalProcess/service")
public class ApproveManagerController {
	
	@Autowired
	private ApproveManagerService approveManagerService;
	
	/**
	 * 筛选条件查询
	 * @return
	 */
	@RequestMapping("screeneCondition")
	public MarvelsResultDTO screeneCondition(){
		try {
			ApproveManageScreeneDTO dto = approveManagerService.screeneCondition();
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), dto);
		} catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error(">>>>>>>审批流程筛选条件查询失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>审批流程筛选条件查询异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	
	
	/**
	 * 审批流程列表查询
	 * @param dto
	 * @return
	 */
	@RequestMapping("listQuery")
	public MarvelsResultDTO listQuery(@RequestBody ApprovalProcessConditionDTO dto){
		try {
			PageInfo<ApprovalProcessInfoDTO> list = approveManagerService.listQuery(dto);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), list);
		} catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error(">>>>>>>审批流程列表查询失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>审批流程列表查询异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		
	}
	
}
